import { createSlice } from "@reduxjs/toolkit";
import axios from "axios";

const channelStore = createSlice({
  name: "channel",
  initialState: {
    channelList: [],
  },
  reducers: {
    addChannel (state, action) {
      state.channelList = action.payload;
    }
  }
})

// 异步请求
export const { addChannel } = channelStore.actions;
const fetchChannlList = () => {
  return async (dispatch) => {
    const res = await axios.get("http://geek.itheima.net/v1_0/channels");
    dispatch(addChannel(res.data.data.channels))
  }
}
export { fetchChannlList }
const reducer = channelStore.reducer;

export default reducer;